﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Geometry.Core;
using Geometry.Service;
using Geometry.Web.Businesses;
using Geometry.Core.Models;

namespace Geometry.Web.Controllers
{
    public class TriangleController : Controller
    {
        private GeometryEntities db;
        private TriangleBusiness business;
        private TriangleService service;
        
        public TriangleController()
        {
            db = new GeometryEntities();
            business = new TriangleBusiness();
            service = new TriangleService();
        }


        //
        // Get: /Triangle/
        public ActionResult Index()
        {
            List<TriangleResult> models = business.StatisticResult();
            return View(models);
        }

      
        public ActionResult Create()
        {
            Triangle model = new Triangle();
            return View(model);
//            return View();
        }

        [HttpPost]
        public ActionResult Create(Triangle model)
        {
            //Triangle i = model;
            if (!service.Validation(model))
                return View(model);

            var t = business.CheckExistTriangle(model);

            if (t == null)
            {
                business.CalculateNewTriangle(model);
            }
            else
            {
                model = t;
            }
          
            return View(model);
        }



       

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}